import java.util.Vector;

/**
 * 敌方坦克
 */
public class enemyTank extends Tank implements Runnable {
    public enemyTank(int x, int y) {
        super(x, y);
    }

    Boolean isLive = true;
    Bullet bullet = null;
    Vector<Bullet> vector = new Vector<>();

    public void shotEnemyTank(){
        if (vector.size()<5){
            switch (getDirect()) {
                case 0:
                    bullet = new Bullet(getX()+12, getY()-10, 0);
                    break;
                case 1:
                    bullet = new Bullet(getX()+60, getY()+12, 1);
                    break;
                case 2:
                    bullet = new Bullet(getX()+12, getY()+65, 2);
                    break;
                case 3:
                    bullet = new Bullet(getX()-12, getY()+12, 3);
                    break;
            }
            vector.add(bullet);
        }
        for (Bullet b: vector
        ) {
            new Thread(b).start();
        }

    }
    @Override
    public void run() {
        while(isLive){
            int n = (int) (Math.random()*5);
            try {
                //射击
                if (n < 4){
                        for (int i = 0; i < n; i++){
                            Thread.sleep(100);
                            shotEnemyTank();
                    }
                }
                setDirect((int) (Math.random()*4));
                for (int i = 0; i < 5 ; i++){
                    outOfRange();
                    switch (getDirect()){
                        case 0:
                            moveUp();
                            break;
                        case 1:
                            moveRight();
                            break;
                        case 2:
                            moveDown();
                            break;
                        case 3:
                            moveLeft();
                            break;
                    }
                    Thread.sleep(100);
                }

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
